<template>
  <div id="global-header">
    <a-row :wrap="false">
      <a-col flex="200px">
        <router-link to="/">
          <div class="title-bar">
              <img alt="logo" class="logo" src="../assets/logo.ico" />
<!--              <div class="title">鸡哥待办事项管理系统</div>-->
          </div>
        </router-link>
      </a-col>
      <a-col flex="auto">
        <a-menu v-model:selectedKeys="current" :items="items" mode="horizontal"
                @click="doMenuClick" />
      </a-col>
      <div class="user-login-status">
        <div v-if="loginUserStore.loginUser.id">
          {{ loginUserStore.loginUser.userName ?? '默认名称' }}
        </div>
        <div v-else>
          <a-button href="/user/login" type="primary">登录</a-button>
        </div>
      </div>
    </a-row>
  </div>

</template>

<script lang="ts" setup>
import { h, ref } from 'vue'
import { HomeOutlined, UserOutlined } from '@ant-design/icons-vue'
import { MenuProps } from 'ant-design-vue'
import { useRouter } from 'vue-router'
import { useLoginUserStore } from '@/stores/useLoginUserStore.ts'
import { userGetLoginUserVoUsingGet } from '@/api/userController.ts'

const loginUserStore = useLoginUserStore()

const current = ref<string[]>(['mail'])
const items = ref<MenuProps['items']>([
  {
    key: '/',
    icon: () => h(HomeOutlined),
    label: '主页',
    title: '主页'
  },
  {
    key: '/my',
    icon: () => h(UserOutlined),
    label: '我的',
    title: '我的'
  },
  {
    key: '/add_task',
    icon: () => h(UserOutlined),
    label: '任务速建',
    title: '任务速建'
  },
  {
    key: '/about',
    label: h('a', { href: 'https://gitee.com/Jigefactory', target: '_blank' }, '关于作者'),
    title: '关于作者'
  }
])


const router = useRouter()
const doMenuClick = ({ key }) => {
  router.push(key)
}

const fetchLoginUser = async () => {
  const res = await userGetLoginUserVoUsingGet()
  if (res.data.code === 0 && res.data.data) {
    loginuser.value = res.data.data
  }
}

</script>

<style>
#global-header {
  width: 100%;
  align-items: center;
}

#global-header :deep(.css-dev-only-do-not-override-1p3hq3p) {
  display: none;
}

.title-bar {
  display: flex;
  align-items: center;
}

.logo {
  height: 48px;
}

.title {
  color: black;
  font-size: 14px;
  margin-left: 12px
}


</style>
